from concepts import *


class BuildBar(GUIElement):
    city = Attribute()

    is_showing_buildings = Attribute(initial = False, writable = True)
    is_destroying        = Attribute(initial = False, writable = True)
    
    def show_buildings(self):
        self.is_showing_buildings = True
        self.is_destroying        = False
    
    def start_destroying(self):
        self.is_showing_buildings = False
        self.is_destroying        = True

    def cancel_action(self):
        self.is_showing_buildings = False
        self.is_destroying        = False
    
    @property
    def has_action(self):
        return self.is_showing_buildings or self.is_destroying


class BuildingsPanel(GUIElement):
    city      = Attribute()
    gameset   = Attribute()
    build_bar = Attribute()
    
    @property
    def is_visible(self):
        return self.build_bar.is_showing_buildings
    
    @property
    def categories(self):
        return self.gameset.categories

    @property
    def selection(self):
        return self.renderer.current_building

    @property
    def has_selection(self):
        return self.selection is not None
    
    def clear_selection(self):
        self.renderer.clear_building()
